package com.java.service.impl;

import com.java.entity.PageBean;
import com.java.entity.PsInspectiontaskDetail;
import com.java.mapper.PsInspectiontaskDetailMapper;
import com.java.service.PsInspectiontaskDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author caiyuan
 * @version 1.0
 * @Date 2020/6/25 4:09 Dream-Seeker
 * @Description
 */
@Service
public class PsInspectiontaskDetailServiceImpl implements PsInspectiontaskDetailService {
    @Autowired
    PsInspectiontaskDetailMapper psInspectiontaskDetailMapper;

    @Override
    public List<PsInspectiontaskDetail> getInspecdetailBylineCodes(String lineCode) {
        return psInspectiontaskDetailMapper.getInspecdetailBylineCodes(lineCode);
    }

    @Override
    public PsInspectiontaskDetail getInspecdetailBytaskId(Integer taskId) {
        return psInspectiontaskDetailMapper.getInspecdetailBytaskId(taskId);
    }

    @Override
    public Integer addPsInspectiontaskDetail(PsInspectiontaskDetail psInspectiontaskMain) {
        return psInspectiontaskDetailMapper.addPsInspectiontaskDetail(psInspectiontaskMain);
    }

    @Override
    public PsInspectiontaskDetail getInspecBypoleCode(String poleCode) {
        return psInspectiontaskDetailMapper.getInspecBypoleCode(poleCode);
    }

    @Override
    public Integer updatePsInspec(PsInspectiontaskDetail psInspectiontaskDetail) {
        return psInspectiontaskDetailMapper.updatePsInspec(psInspectiontaskDetail);
    }

    @Override
    public PageBean<PsInspectiontaskDetail> findByPageInspecDetail(Integer currentPage, String lineCode, String bugTypeName, String bugLevelName, String findthetimestart, String findthetimeend, String issuedTimestart, String issuedTimeend) {
        HashMap<String, Object> map = new HashMap<String, Object>();
        PageBean<PsInspectiontaskDetail> pageBean = new PageBean<PsInspectiontaskDetail>();

        //每页显示的数据
        int pageSize = 5;
        pageBean.setPageSize(pageSize);

        //封装总记录数
        int totalCount = psInspectiontaskDetailMapper.selectCount(
                lineCode,
                bugTypeName,
                bugLevelName,
                findthetimestart,
                findthetimeend);
        pageBean.setTotalCount(totalCount);

        //封装总页数
        double tc = totalCount;
        Double num = Math.ceil(tc / pageSize);//向上取整
        pageBean.setTotalPage(num.intValue());

        if (currentPage > pageBean.getTotalPage()) {
            //封装当前页数
            pageBean.setCurrPage(pageBean.getTotalPage());
        } else if (currentPage < 0) {
            pageBean.setCurrPage(1);
        } else {
            pageBean.setCurrPage(currentPage);
        }
        map.put("start", (currentPage - 1) * pageSize);
        map.put("size", pageBean.getPageSize());
        map.put("lineCode", lineCode);
        map.put("bugTypeName", bugTypeName);
        map.put("bugLevelName", bugLevelName);
        map.put("findthetimestart", findthetimestart);
        map.put("findthetimeend", findthetimeend);

        //封装每页显示的数据
        List<PsInspectiontaskDetail> lists = psInspectiontaskDetailMapper.findByPageInspecDetail(map);
        pageBean.setLists(lists);
        return pageBean;
    }


}
